

import org.authsum.stitches.external.*
import org.authsum.stitches.service.*
import org.authsum.stitches.Helper

class TagsControllerTests extends GroovyTestCase {
	def helper

    def stitchesService
	
	
	void testEditTag() {
		
		Long tagId = helper.getTagId(name:"testEditTag")
		
		def controller = new TagsController()	
    	controller.stitchesService  = stitchesService
		controller.request.parameters = ['tagId':tagId.toString()]
		controller.editTag()
		
	}
	
	void testDeleteTag() {
		
		Map parms = ['name':'testDeleteTag']
		Long tagId = helper.getTagId(parms)
		
		
		def controller = new TagsController()	
    	controller.stitchesService  = stitchesService
		controller.request.parameters = ['tagId':tagId.toString()]
		controller.deleteTag()
	}
	
	

	
	void testAddTagToContent()  {
		//create contentdef
		Long contentDefId = helper.getContentDefId(name:"testAddTagToContent")
		
		
		//create content
		Long contentId = helper.getContentId(contentDefId:contentDefId,name:"testAddTagToContent")
		//create content version
		Long contentVersionId = helper.getContentVersionId(contentId:contentId)
		
		Long tagId = helper.getTagId(name:'testAddTagToContent')
		
		
		
		def controller = new TagsController()	
    	controller.stitchesService  = stitchesService
		controller.request.parameters = ['tagId':tagId.toString(),'contentVersionId':contentVersionId.toString()]
		controller.addTagToContent()
		
	}
	
	
	
	
   void testIndex() { 

		def controller = new TagsController()
    	controller.stitchesService  = stitchesService
		controller.index()   	
   		
   }
	
	void testSaveNewTag() {
		def controller = new TagsController()
    	controller.stitchesService  = stitchesService
		controller.request.parameters = ['name':"testSaveNewTag"]
		controller.saveTag()  
			
	}
	
	
	void testSaveExistingTag() {
		Long tagId = helper.getTagId(name:"testSaveExistingTag")
		def controller = new TagsController()	
    	controller.stitchesService  = stitchesService
		//controller.helper = helper
		controller.request.parameters = ['name':"testSaveExistingTag2",id:tagId.toString()]
		controller.saveTag()  
		//let's verify it worked
		def tagHolder = helper.findTagById(tagId)
		assertTrue tagHolder.name == 'testSaveExistingTag2'
			
	}
	
	
}
